/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.account.DataSource.DataImport;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.datasource.DataSourceManager;
/*    */ import com.zimbra.cs.gal.GalGroup;
/*    */ import com.zimbra.cs.gal.GalImport;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.type.DataSourceType;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public final class SyncGalAccount
/*    */   extends AdminDocumentHandler
/*    */ {
/* 41 */   private static final String[] TARGET_ACCOUNT_PATH = { "account", "id" };
/*    */   
/*    */   protected String[] getProxiedAccountPath()
/*    */   {
/* 45 */     return TARGET_ACCOUNT_PATH;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 50 */     notes.add("TDB");
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 56 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 57 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 59 */     ZimbraLog.addToContext("aname", getAuthenticatedAccount(zsc).getName());
/*    */     
/* 61 */     for (Element accountEl : request.listElements("account")) {
/* 62 */       String accountId = accountEl.getAttribute("id");
/* 63 */       account = prov.getAccountById(accountId);
/* 64 */       if (account == null) {
/* 65 */         throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
/*    */       }
/* 67 */       ZimbraLog.addToContext("name", account.getName());
/*    */       
/* 69 */       for (Element dsEl : accountEl.listElements("datasource")) {
/* 70 */         String by = dsEl.getAttribute("by");
/* 71 */         String name = dsEl.getText();
/* 72 */         DataSource ds = by.equals("id") ? account.getDataSourceById(name) : account.getDataSourceByName(name);
/* 73 */         if (ds == null) {
/* 74 */           throw AccountServiceException.NO_SUCH_DATA_SOURCE(name);
/*    */         }
/* 76 */         if (ds.getType().equals(DataSourceType.gal))
/*    */         {
/*    */ 
/* 79 */           boolean fullSync = dsEl.getAttributeBool("fullSync", false);
/* 80 */           boolean reset = dsEl.getAttributeBool("reset", false);
/* 81 */           int fid = ds.getFolderId();
/*    */           
/* 83 */           DataSource.DataImport dataImport = DataSourceManager.getInstance().getDataImport(ds);
/* 84 */           if ((dataImport instanceof GalImport)) {
/* 85 */             ((GalImport)dataImport).importGal(fid, reset ? reset : fullSync, reset);
/*    */           }
/*    */           
/* 88 */           Domain domain = prov.getDomain(account);
/* 89 */           GalGroup.flushCache(domain);
/*    */         }
/*    */       } }
/*    */     Account account;
/* 93 */     return zsc.createElement(AdminConstants.SYNC_GAL_ACCOUNT_RESPONSE);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/SyncGalAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */